<template>
	<view class="container">
		<view class="log" style="text-align: center; height: 220px;">
			<image src="/static/头像.jpg" style="
			width: 250prx;
			height: 250prx;
			scale: 0.4;"></image>
		</view>
		<uni-forms ref="form" :model="user" :rules="rules">
			<uni-forms-item label="" name="name">
		
				<uni-easyinput v-model="user.username" placeholder="请输入用户名" />
			</uni-forms-item>
			<uni-forms-item label="" name="password">
		
				<uni-easyinput type="password" v-model="user.password" placeholder="请输入密码" />
			</uni-forms-item>
			<uni-forms-item label="" name="">
				<button type="primary" size="default" @click="login">登录</button> <!-- 设置click事件方法  -->
			</uni-forms-item>
		</uni-forms>
		<button @click="goregister">去注册</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				rules: {
					username: {
						rules: [{
							required: true,
							errorMessage: '请输入姓名'
						}]
					},
					password: {
						rules: [{
							required: true,
							errorMessage: '请输入用户密码'
						}]
					}
				},
				user: {
					username: '',
					password: ''
				}
			}
		},
		methods: {
			goregister(){
						uni.navigateTo({
							url:"/pages/my/register"
						})
					},
					login(e) {
						uni.request({
							url: 'http://localhost:8090/freshmenapp/user/login',
							method: 'POST',
							data: this.user,
							success: res => {
								if (res.data.success) {
									this.list = res.data.list
									uni.showToast({
										title: '成功',
										icon: 'none'
									});
								}
								uni.setStorage({
									key: 'userinfo',
									data: res.data.data
								})
								uni.navigateBack()
							},
							fail: () => {
			
							},
							complete: () => {
			
							}
						});
						onLoad: () => {
							uni.onTabBarMidButtonTap(function(e) {
								console.log(e)
							})
						}
			
						this.$refs.form.validate().then(() => {
							
							console.log(this.user.name);
			
						})
			
			
					}
		}
	}
</script>

<style>
.container {
		padding: 20rpx;
	}
</style>
